﻿#region Using Directives

using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.IO;
using EnvDTE;
using EnvDTE100;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TeamArchitect.PowerTools.Features;

#endregion

namespace FeatureBuilder.ContribLib.ValueProviders
{

    /// <summary>
    /// Returns the Debug directory for the project.
    /// </summary>
    [DisplayName("Project Debug TargetDir Provider")]
    [Description("Returns the Debug directory for the project")]
    [Category("IDE")]
    public class ProjectDebugTargetDirProvider : ValueProvider
    {

        /// <summary>
        /// Gets the ServiceProvider that we will use to get a reference to DTE.
        /// </summary>
        [Import(typeof(SVsServiceProvider))]
        public IServiceProvider ServiceProvider { get; private set; }

        /// <summary>
        /// Gets the Feature Extension instance for this invocation
        /// of the Condition
        /// </summary>
        [Import(AllowDefault = true)]
        public IFeatureExtension Feature { get; private set; }

        /// <summary>
        /// Returns the path to the Debug directory for the project.
        /// Note: currently it returns the path for the first project. Maybe we should changes this!!
        /// </summary>
        public override object Evaluate()
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE.DTE;
            if (dte == null)
                return null;
            Solution4 s = dte.Solution as Solution4;

            if (s == null)
                return null;
            Project p = s.Projects.Item(1);

            string folderPath = Path.GetDirectoryName(p.FullName);
            string filePath = Path.Combine(folderPath, "bin\\Debug");

            return filePath;
        }
    }
}